package com.infodms.dms.actions.sales.customerInfoManage;

import java.sql.ResultSet;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.infodms.dms.actions.common.FileUploadManager;
import com.infodms.dms.bean.AclUserBean;
import com.infodms.dms.common.Constant;
import com.infodms.dms.common.ErrorCodeConstant;
import com.infodms.dms.common.getCompanyId.GetOemcompanyId;
import com.infodms.dms.common.materialManager.MaterialGroupManagerDao;
import com.infodms.dms.dao.common.BaseDao;
import com.infodms.dms.dao.common.CommonDAO;
import com.infodms.dms.dao.sales.customerInfoManage.SalesVehicleReturnDAO;
import com.infodms.dms.dao.sales.marketmanage.planmanage.ActivitiesPlanManageDao;
import com.infodms.dms.exception.BizException;
import com.infodms.dms.po.TcUserPO;
import com.infodms.dms.po.TmVehiclePO;
import com.infodms.dms.po.TtAsRepairOrderPO;
import com.infodms.dms.po.TtAsWrApplicationPO;
import com.infodms.dms.po.TtDealerActualSalesPO;
import com.infodms.dms.po.TtVsActualSalesReturnPO;
import com.infodms.dms.util.CommonUtils;
import com.infodms.dms.util.sequenceUitl.SequenceManager;
import com.infoservice.mvc.context.ActionContext;
import com.infoservice.mvc.context.ActionContextExtend;
import com.infoservice.mvc.context.RequestWrapper;
import com.infoservice.po3.bean.PO;
import com.infoservice.po3.bean.PageResult;
import static com.infodms.dms.actions.sales.customerInfoManage.SalesReport.setStr ;

public class SalesVehicleReturn extends BaseDao{

	public Logger logger = Logger.getLogger(SalesVehicleReturn.class);
	private ActionContext act = ActionContext.getContext();
	private static final SalesVehicleReturn dao = new SalesVehicleReturn();
	public static final SalesVehicleReturn getInstance() {
		return dao;
	}
	RequestWrapper request = act.getRequest();
	private final String  salesVehicleReturnReqInitURL = "/jsp/sales/customerInfoManage/salesVehicleReturnReqInit.jsp";
	private final String  salesVehicleReturnCheckInitURL = "/jsp/sales/customerInfoManage/salesVehicleReturnCheckInit.jsp";
	private final String  salesVehicleReturnQueryInitURL = "/jsp/sales/customerInfoManage/salesVehicleReturnQueryInit.jsp";
	private final String  salesVehicleReturnCheckQueryInitURL = "/jsp/sales/customerInfoManage/salesVehicleReturnCheckQueryInit.jsp";
	private final String  returnVehicleInfoURL = "/jsp/sales/customerInfoManage/returnVehicleInfo.jsp";
	private final String  toCheckReturnVehicleURL = "/jsp/sales/customerInfoManage/toCheckReturnVehicle.jsp";
	
	/** 
	* @Title	  : salesInfoChangeInit 
	* @Description: 实销退车申请页面初始化 
	* @throws 
	* @LastUpdate :2010-6-28
	*/
	public void salesVehicleReturnReqInit(){
		AclUserBean logonUser = null;
		try {
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);
			Long poseId = logonUser.getPoseId();
			List<Map<String, Object>> areaList1 = MaterialGroupManagerDao.getDealerBusiness(poseId.toString());
			
			act.setOutData("areaList", areaList1);
			act.setForword(salesVehicleReturnReqInitURL);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "实销退车申请页面初始化");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/**
	 * 获取实体列表
	 */
	/*public void getEntity() {
		AclUserBean logonUser = null;
		try {
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);
			Long orgId = logonUser.getOrgId() ;
			
			List<Map<String, Object>> entityList = SalesVehicleReturnDAO.getEntity(orgId) ;
			
			act.setOutData("entityList", entityList) ;
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "获取实体列表");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}*/
	
	/** 
	* @Title	  : salesInfoChangeInit 
	* @Description: 查询实销车辆 
	* @throws 
	* @LastUpdate :2010-6-28
	*/
	public void querySalesedVehicleList(){
		AclUserBean logonUser = null;
		try {
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);	
			String vin =  CommonUtils.checkNull(request.getParamValue("vin"));
			vin = setStr(vin, "L") ;	// 由于当前（2011/3/29）所有的vin均存在“L”，故以此作为查询条件加快查询速度
			if (null != vin && !"".equals(vin)) {
				vin = vin.trim();
			}
			String areaId = request.getParamValue("areaId");
	        String dealerIds = logonUser.getDealerId();
			Integer curPage = request.getParamValue("curPage") != null ? Integer
					.parseInt(request.getParamValue("curPage"))
					: 1; // 处理当前页
					
			PageResult<Map<String, Object>> ps = SalesVehicleReturnDAO.getSalesedVehicleList(areaId,dealerIds, vin, Constant.PAGE_SIZE, curPage);
			act.setOutData("ps", ps);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "查询实销车辆 ");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/** 
	* @Title	  : returnVehicleInfo 
	* @Description: 查询实销信息
	* @throws 
	* @LastUpdate :2010-6-28
	*/
	public void returnVehicleInfo(){
		AclUserBean logonUser = null;
		try {
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);	
			String vehicleId =  CommonUtils.checkNull(request.getParamValue("vehicle_id"));
			Map<String, String> salesVehicleInfo = SalesVehicleReturnDAO.getSalesVehicleInfo(vehicleId);
			Map<String, String> salesCusInfo = SalesVehicleReturnDAO.getSalesCusInfo(vehicleId);
			String isFleet = String.valueOf(salesCusInfo.get("IS_FLEET"));
			String ctmType = String.valueOf(salesCusInfo.get("CTM_TYPE"));
			TmVehiclePO tmv = new TmVehiclePO() ;
			tmv.setVehicleId(Long.parseLong(vehicleId)) ;
			
			Double scCost = SalesVehicleReturnDAO.getScCost(vehicleId) ;	// 售后费用
			
			act.setOutData("scCost", scCost);
			act.setOutData("isFleet", isFleet);
			act.setOutData("ctmType", ctmType);
			act.setOutData("salesVehicleInfo", salesVehicleInfo);
			act.setOutData("salesCusInfo", salesCusInfo);
			act.setForword(returnVehicleInfoURL);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "查询实销车辆 信息");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/** 
	* @Title	  : reportSubmit 
	* @Description: 退车提交
	* @throws 
	* @LastUpdate :2010-6-28
	*/
	public void reportSubmit(){
		AclUserBean logonUser = null;
		try {
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);	
			String orderId =  CommonUtils.checkNull(request.getParamValue("orderId"));			//实销id
			String vehicleId = CommonUtils.checkNull(request.getParamValue("vehicleId"));		//车辆id
			String returnType = CommonUtils.checkNull(request.getParamValue("returnType"));		//退车类型
			String returnReason = CommonUtils.checkNull(request.getParamValue("returnReason"));	//退车原因
			String scCost = CommonUtils.checkNull(request.getParamValue("scCost"));	//售后费用
			Double mScCost = Double.parseDouble(scCost) ;
			
			String []fjids = request.getParamValues("fjid");					    			//附件ID
			
			TmVehiclePO tmVehiclePO = new TmVehiclePO();
			tmVehiclePO.setVehicleId(Long.parseLong(vehicleId));
			List vList = dao.select(tmVehiclePO);
			Long dealerId = ((TmVehiclePO)vList.get(0)).getDealerId();
			Long oemCompanyId = GetOemcompanyId.getOemCompanyId(logonUser);
		
			TtVsActualSalesReturnPO returnPO = new TtVsActualSalesReturnPO();
			String returnId = SequenceManager.getSequence("") ;
			returnPO.setReturnId(Long.parseLong(returnId));
			returnPO.setOrderId(Long.parseLong(orderId));	
			returnPO.setOemCompanyId(oemCompanyId);
			returnPO.setDealerId(dealerId);
			if (null != returnReason && !"".equals(returnReason)) {
				returnPO.setReturnReason(returnReason.trim());
			}
			if (null != returnType && !"".equals(returnType)) {
				returnPO.setReturnType(Long.parseLong(returnType)) ;
			}
			
			String para = CommonDAO.getPara(Constant.SALE_RETURN_PARA_SH_PRICE.toString()) ;
			if(Integer.parseInt(para) > 0) {
				// 有售后费用状态变更为待总部审核，无售后费用的状态变更为待事业部审核
				if(mScCost > 0) {
					returnPO.setStatus(Constant.RETURN_CHECK_STATUS_01);
				} else {
					returnPO.setStatus(Constant.RETURN_CHECK_STATUS_SYB);
				}
			} else {
				returnPO.setStatus(Constant.RETURN_CHECK_STATUS_01);
			}
			returnPO.setReqDate(new Date());
			returnPO.setCreateDate(new Date());
			returnPO.setCreateBy(logonUser.getUserId());
			dao.insert(returnPO);
			TmVehiclePO valuePO = new TmVehiclePO();
			valuePO.setLockStatus(Constant.LOCK_STATUS_05);
			dao.update(tmVehiclePO, valuePO);
			
			//附件添加
			FileUploadManager.fileUploadByBusiness(returnId, fjids, logonUser);
			
			salesVehicleReturnReqInit();
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "实销退车提交");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/** 
	* @Title	  : salesVehicleReturnQueryInit 
	* @Description: 退车查询页面初始化
	* @throws 
	* @LastUpdate :2010-6-28
	*/
	public void salesVehicleReturnQueryInit(){
		AclUserBean logonUser = null;
		try {
			  ActionContextExtend atx = (ActionContextExtend) ActionContext.getContext();
				String reqURL = atx.getRequest().getContextPath();
				if("/CVS-SALES".equals(reqURL.toUpperCase())){
					act.setOutData("returnValue", 1);
				}else{
					act.setOutData("returnValue", 2);
				}
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);	
			Long poseId = logonUser.getPoseId();
			List<Map<String, Object>> areaList1 = MaterialGroupManagerDao.getDealerBusiness(poseId.toString());
			act.setOutData("areaList", areaList1);
			act.setForword(salesVehicleReturnQueryInitURL);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "实销退车申请页面初始化");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/** 
	* @Title	  : queryReturnReqList 
	* @Description: 退车查询结果展示 
	* @throws 
	* @LastUpdate :2010-6-28
	*/
	public void queryReturnReqList_DLR(){
		AclUserBean logonUser = null;
		try {
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);	
			String vin =  CommonUtils.checkNull(request.getParamValue("vin"));
			if (null != vin && !"".equals(vin)) {
				vin = vin.trim();
			}
			String dealerIds = logonUser.getDealerId();
			String areaId = CommonUtils.checkNull(request.getParamValue("areaId"));
			Integer curPage = request.getParamValue("curPage") != null ? Integer.parseInt(request.getParamValue("curPage")): 1; // 处理当前页
			PageResult<Map<String, Object>> ps = SalesVehicleReturnDAO.getReturnReqList_DLR(dealerIds,areaId, vin, Constant.PAGE_SIZE, curPage);
			act.setOutData("ps", ps);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "实销退车申请页面初始化");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	
	public void salesVehicleReturnCheckInitNum(String areId){
		AclUserBean logonUser = null;
		try {
			ActionContextExtend atx = (ActionContextExtend) ActionContext.getContext();
			String reqURL = atx.getRequest().getContextPath();
			if("/CVS-SALES".equals(reqURL.toUpperCase())){
				act.setOutData("returnValue", 1);
			}else{
				act.setOutData("returnValue", 2);
			}
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);	
			List<Map<String, Object>> areaList = MaterialGroupManagerDao.getPoseIdBusiness(logonUser.getPoseId().toString());
			act.setOutData("areaList", areaList);
			if(areId.equals("") || areId==null){
				areId="1";
			}
			act.setOutData("areId", areId);
			act.setForword(salesVehicleReturnCheckInitURL);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "实销退车申请页面初始化");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/** 
	* @Title	  : salesVehicleReturnCheckInit 
	* @Description: 退车审核页面初始化
	* @throws 
	* @LastUpdate :2010-6-28
	*/
	public void salesVehicleReturnCheckInit(){
		AclUserBean logonUser = null;
		try {
			ActionContextExtend atx = (ActionContextExtend) ActionContext.getContext();
			String reqURL = atx.getRequest().getContextPath();
			if("/CVS-SALES".equals(reqURL.toUpperCase())){
				act.setOutData("returnValue", 1);
			}else{
				act.setOutData("returnValue", 2);
			}
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);	
			Long poseId = logonUser.getPoseId() ;
			
			List<Map<String, Object>> entityList = SalesVehicleReturnDAO.getEntity(poseId) ;
			List<Map<String, Object>> areaList = MaterialGroupManagerDao.getPoseIdBusiness(logonUser.getPoseId().toString());
//			getEntity() ;
			act.setOutData("entityList", entityList) ;
			act.setOutData("areaList", areaList);
			act.setForword(salesVehicleReturnCheckInitURL);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "实销退车申请页面初始化");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/** 
	* @Title	  : salesVehicleReturnCheckInit 
	* @Description: 查询带审核退车信息
	* @throws 
	* @LastUpdate :2010-6-28
	*/
	public void queryToReturnVehicleList(){
		AclUserBean logonUser = null;
		try {
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);	
			String vin =  CommonUtils.checkNull(request.getParamValue("vin"));
			String dealerCode = CommonUtils.checkNull(request.getParamValue("dealerCode"));
			String entity = CommonUtils.checkNull(request.getParamValue("entity"));
			Long orgId = logonUser.getOrgId() ;
			String dutyType = logonUser.getDutyType() ;
			String status = null ;
			
			if (null != vin && !"".equals(vin)) {
				vin = vin.trim();
			}
			
			if (null != dealerCode && !"".equals(dealerCode)) {
				dealerCode = dealerCode.trim();
			}
			
			if(CommonUtils.isNullString(entity)) {
				entity = getEntityStr() ;
			}
			
			if(Constant.DUTY_TYPE_COMPANY.toString().equals(dutyType)) {
				orgId = null ;
				status = Constant.RETURN_CHECK_STATUS_01.toString() ;
			} else if (Constant.DUTY_TYPE_LARGEREGION.toString().equals(dutyType)) {
				status = Constant.RETURN_CHECK_STATUS_SYB.toString() ;
			}
			
			Integer curPage = request.getParamValue("curPage") != null ? Integer.parseInt(request.getParamValue("curPage")) : 1; // 处理当前页

			PageResult<Map<String, Object>> ps = SalesVehicleReturnDAO.getToReturnVehicleList_Entity(dutyType, orgId , logonUser.getUserId(),status, entity, vin, dealerCode, Constant.PAGE_SIZE, curPage);
			
			// PageResult<Map<String, Object>> ps = SalesVehicleReturnDAO.getToReturnVehicleList(entity,vin,dealerCode, Constant.PAGE_SIZE, curPage);
			act.setOutData("ps", ps);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "实销退车审核:查询带审核退车信息");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/** 
	* @Title	  : salesVehicleReturnCheckInit 
	* @Description: 审核退车信息
	* @throws 
	* @LastUpdate :2010-6-28
	*/
	public void toCheckReturnVehicle(){
		AclUserBean logonUser = null;
		try {
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);	
			
			String dutyType = logonUser.getDutyType() ;
			
			List<Map<String, Object>> areaList = MaterialGroupManagerDao.getPoseIdBusiness(logonUser.getPoseId().toString());
			act.setOutData("areaList", areaList);
			String vehicleId =  CommonUtils.checkNull(request.getParamValue("vehicle_id"));
			String return_id =  CommonUtils.checkNull(request.getParamValue("return_id"));
			
			Map<String, String> salesVehicleInfo = SalesVehicleReturnDAO.getSalesVehicleInfo(vehicleId);
			Map<String, String> salesCusInfo = SalesVehicleReturnDAO.getSalesCusInfo(vehicleId);
			Map<String, String> returnReason = SalesVehicleReturnDAO.getReturnReason(return_id);
			String isFleet = String.valueOf(salesCusInfo.get("IS_FLEET"));
			String ctmType = String.valueOf(salesCusInfo.get("CTM_TYPE"));
			//根据return_id查询上传附件
			List<Map<String, Object>> attachList = ActivitiesPlanManageDao.getInstance().getAttachInfos(return_id);
			if(null!=attachList&&attachList.size()!=0){
				act.setOutData("attachList", attachList);
			}
			
			String entity = request.getParamValue("entity");
			
			Double scCost = SalesVehicleReturnDAO.getScCost(vehicleId) ;	// 售后费用
			
			act.setOutData("dutyType", dutyType) ;
			act.setOutData("scCost", scCost);
			act.setOutData("entity", entity);
			act.setOutData("isFleet", isFleet);
			act.setOutData("ctmType", ctmType);
			act.setOutData("salesVehicleInfo", salesVehicleInfo);
			act.setOutData("salesCusInfo", salesCusInfo);
			act.setOutData("returnReason", returnReason);
			act.setOutData("returnId", return_id);
			act.setForword(toCheckReturnVehicleURL);
			
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "实销退车审核:查询带审核退车信息");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	public void isChkUser () {
		AclUserBean logonUser = null;
		try {
			String vehicleId =  CommonUtils.checkNull(request.getParamValue("vehicleId"));
			String returnId =  CommonUtils.checkNull(request.getParamValue("returnId"));
			
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);	
			Long userId = logonUser.getUserId() ;
			
			if (SalesVehicleReturnDAO.isScCost(vehicleId) && !SalesVehicleReturnDAO.isChkUser(userId)) {
				TcUserPO tcu = new TcUserPO() ;
				tcu.setUserId(userId) ;
				List<TcUserPO> tcuList = dao.select(tcu) ;
				
				String acnt = tcuList.get(0).getAcnt() ;
				
				act.setOutData("acnt", acnt) ;
			}
			
			act.setOutData("vehicleId", vehicleId) ;
			act.setOutData("returnId", returnId) ;
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "实销退车审核:检查审核权限");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/** 
	* @Title	  : salesVehicleReturnCheckInit 
	* @Description: 审核退车:提交
	* @throws 
	* @LastUpdate :2010-6-28
	*/
	public void returnVehicleSubmit(){
		AclUserBean logonUser = null;
		try {
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);	
			String vehicleId =  CommonUtils.checkNull(request.getParamValue("vehicleId"));
			String vin = CommonUtils.checkNull(request.getParamValue("vin")) ;
			String return_id =  CommonUtils.checkNull(request.getParamValue("returnId"));//退车申请id
			String orderId =  CommonUtils.checkNull(request.getParamValue("orderId"));   //实销id
			String isPass = CommonUtils.checkNull(request.getParamValue("isPass"));      //审核结果，1：通过，0：驳回
			String chk_remark = CommonUtils.checkNull(request.getParamValue("chk_remark"));//审核描述
			
			//修改退车申请审核状态
			TtVsActualSalesReturnPO tempReturnPO = new TtVsActualSalesReturnPO();
			tempReturnPO.setReturnId(Long.parseLong(return_id));
			
			TtVsActualSalesReturnPO valueReturnPO = new TtVsActualSalesReturnPO();
			if ("1".equals(isPass)) {
				valueReturnPO.setStatus(Constant.RETURN_CHECK_STATUS_02);//审核通过
				/*//修改车辆状态
				TmVehiclePO tempVehiclePO = new TmVehiclePO();
				tempVehiclePO.setVehicleId(Long.parseLong(vehicleId));
				TmVehiclePO valueVehiclePO = new TmVehiclePO();
				valueVehiclePO.setFreeTimes(0) ; 						// 保养次数
				valueVehiclePO.setClaimTacticsId(new Long("")) ;				// 三包id
				valueVehiclePO.setHistoryMile(new Double(0)) ;			// 行驶公里数
				valueVehiclePO.setMeterMile(new Double(0)) ;			// 表盘公里数
				valueVehiclePO.setMileage(new Double(0)) ;				// 里程数
				valueVehiclePO.setStartMileage(new Double(0)) ;			// 开始里程数
				valueVehiclePO.setPurchasedDate(null) ;					// 更新购车日期
				valueVehiclePO.setLifeCycle(Constant.VEHICLE_LIFE_03);
				valueVehiclePO.setLockStatus(Constant.LOCK_STATUS_01) ; // 车辆锁定状态修改，退车锁定-->正常状态
				dao.update(tempVehiclePO,valueVehiclePO);*/
				//修改车辆状态
				SalesVehicleReturnDAO.updateVechile(Long.parseLong(vehicleId)) ;
				
				// 更新工单退车状态
				TtAsRepairOrderPO oldTaro = new TtAsRepairOrderPO() ;
				oldTaro.setVin(vin) ;
				TtAsRepairOrderPO newTaro = new TtAsRepairOrderPO() ;
				newTaro.setIsReturn(Constant.IF_TYPE_YES) ;
				dao.update(oldTaro, newTaro) ;
				
				// 更新索赔单退车状态
				TtAsWrApplicationPO oldTawa = new TtAsWrApplicationPO() ;
				oldTawa.setVin(vin) ;
				TtAsWrApplicationPO newTawa = new TtAsWrApplicationPO() ;
				newTawa.setIsReturn(Constant.IF_TYPE_YES) ;
				dao.update(oldTawa, newTawa) ;
				
				//修改实销信息：已退车
				TtDealerActualSalesPO tempSalesPO = new TtDealerActualSalesPO();
				tempSalesPO.setOrderId(Long.parseLong(orderId));
				TtDealerActualSalesPO valueSalesPO = new TtDealerActualSalesPO();
				valueSalesPO.setIsReturn(Constant.IF_TYPE_YES);
				valueSalesPO.setReturnDate(new Date());
				dao.update(tempSalesPO, valueSalesPO);
			}else{
				//修改车辆状态
				TmVehiclePO tempVehiclePO = new TmVehiclePO();
				tempVehiclePO.setVehicleId(Long.parseLong(vehicleId));
				TmVehiclePO valueVehiclePO = new TmVehiclePO();
				valueVehiclePO.setLifeCycle(Constant.VEHICLE_LIFE_04);
				valueVehiclePO.setLockStatus(Constant.LOCK_STATUS_01) ; // 车辆锁定状态修改，退车锁定-->正常状态
				dao.update(tempVehiclePO,valueVehiclePO);
				
				valueReturnPO.setStatus(Constant.RETURN_CHECK_STATUS_03);//驳回
			}
			if (!"".equals(chk_remark)) {
				valueReturnPO.setChkRemark(chk_remark.trim());
			}
			valueReturnPO.setChkDate(new Date());
			valueReturnPO.setUpdateBy(logonUser.getUserId());
			valueReturnPO.setUpdateDate(new Date());
			dao.update(tempReturnPO, valueReturnPO);
			
			salesVehicleReturnCheckInit();
			
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "审核退车:提交");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/** 
	* @Title	  : salesVehicleReturnCheckQueryInit 
	* @Description: 实销退车审核查询
	* @throws 
	* @LastUpdate :2010-6-28
	*/
	public void salesVehicleReturnCheckQueryInit(){
		AclUserBean logonUser = null;
		try {
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);
			ActionContextExtend atx = (ActionContextExtend) ActionContext.getContext();
			String reqURL = atx.getRequest().getContextPath();
			if("/CVS-SALES".equals(reqURL.toUpperCase())){
				act.setOutData("returnValue", 1);
			}else{
				act.setOutData("returnValue", 2);
			}
			
			List<Map<String, Object>> entityList = SalesVehicleReturnDAO.getEntity(logonUser.getPoseId()) ;

			act.setOutData("entityList", entityList) ;
			
			List<Map<String, Object>> areaList = MaterialGroupManagerDao.getPoseIdBusiness(logonUser.getPoseId().toString());
			act.setOutData("areaList", areaList);
			act.setForword(salesVehicleReturnCheckQueryInitURL);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "实销退车申请页面初始化");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/** 
	* @Title	  : salesVehicleReturnCheckQueryInit 
	* @Description: 实销退车审核查询信息展示
	* @throws 
	* @LastUpdate :2010-6-28
	*/
	public void queryReturnCheckList(){
		AclUserBean logonUser = null;
		try {
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);	
			String vin =  CommonUtils.checkNull(request.getParamValue("vin"));
			String dealerCode =  CommonUtils.checkNull(request.getParamValue("dealerCode"));
			String status = CommonUtils.checkNull(request.getParamValue("status"));					//状态
			String checkstartDate=request.getParamValue("checkstartDate");		//审核开始日期
			String checkendDate=request.getParamValue("checkendDate");  		//审核结束日期
			String salstartDate=request.getParamValue("salstartDate");//实销开始日期
			String salendDate=request.getParamValue("salendDate");//实销结束日期
			String orgId = CommonUtils.checkNull(request.getParamValue("orgId")) ;	// 大区id
			String entity = CommonUtils.checkNull(request.getParamValue("entity"));
			
			String dutyType = logonUser.getDutyType() ;
			
			if(Constant.DUTY_TYPE_LARGEREGION.toString().equals(dutyType)) {
				orgId = logonUser.getOrgId().toString() ;
			}
			
			if(CommonUtils.isNullString(entity)) {
				entity = getEntityStr() ;
			}
			
			if (null != dealerCode && !"".equals(dealerCode)) {
				dealerCode = dealerCode.trim();
			}
			if (null != vin && !"".equals(vin)) {
				vin = vin.trim();
			}
			Integer curPage = request.getParamValue("curPage") != null ? Integer.parseInt(request.getParamValue("curPage")) : 1; // 处理当前页
					/*String areaId="";
					if(request.getParamValue("areaId")!=null&&request.getParamValue("areaId")!=""){
						areaId=request.getParamValue("areaId");
					}else{
						areaId=GetCommonArea.getMyArea();
					}*/
			PageResult<Map<String, Object>> ps = SalesVehicleReturnDAO.getReturnCheckList(logonUser.getUserId(), dutyType, orgId, checkstartDate,checkendDate,salstartDate,salendDate,entity,vin, status,dealerCode,Constant.PAGE_SIZE, curPage);
			act.setOutData("ps", ps);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "实销退车审核查询信息展示");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	public String getEntityStr() {
		AclUserBean logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER) ;	
		
		List<Map<String, Object>> salesRetList = SalesVehicleReturnDAO.getEntity(logonUser.getPoseId()) ;
		
		StringBuffer entityStr = new StringBuffer("") ;
		
		if(!CommonUtils.isNullList(salesRetList)) {
			int len = salesRetList.size() ;
			
			for(int i=0; i<len; i++) {
				if(CommonUtils.isNullString(entityStr.toString())) {
					entityStr.append(salesRetList.get(i).get("PRODUCE_BASE").toString()) ;
				} else {
					entityStr.append(",").append(salesRetList.get(i).get("PRODUCE_BASE").toString()) ;
				}
			}
		}
		
		return entityStr.toString() ;
	}
	@Override
	protected PO wrapperPO(ResultSet rs, int idx) {
		// TODO Auto-generated method stub
		return null;
	}

}
